package com.yanqu.road.dao.impl.activity.busyfarming;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.busyfarming.BusyFarmingGradeInfo;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class BusyFarmingGradeInfoDaoImpl extends TempDao {


    public static String getBusyFarmingGradeInfoSql = "select * from t_s_activity_guoyuan_grade where activityId = ? order by id";
    public List<BusyFarmingGradeInfo> getBusyFarmingGradeInfo(int activityId) {
        ResultSet rs = null;
        CallableStatement call = null;
        List<BusyFarmingGradeInfo> result = new ArrayList<>();
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getBusyFarmingGradeInfoSql);
            call.setInt(1, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                BusyFarmingGradeInfo data = new BusyFarmingGradeInfo();
                data.setId(rs.getInt("id"));
                data.setName(rs.getString("name"));
                data.setIntegral(rs.getInt("integral"));
                result.add(data);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return result;
    }
}
